﻿using System.Threading;
using System.Web.Mvc;
using Castle.Core.Logging;
using Web7.Container.Localization;
using Web7.Utilities;

namespace Web7.Container.Controllers
{
    public class BaseController : Controller
    {
       

        /// <summary>
        /// 日志记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        protected ILogger Logger<T>()
        {
            IDependencyResolver dependencyResolver = DependencyResolver.Current;
            ILogger logger = dependencyResolver.GetService<ILoggerFactory>().Create(typeof(T));
            return logger;
        }

        /// <summary>
        /// 日志记录
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        protected ILogger Logger()
        {
            IDependencyResolver dependencyResolver = DependencyResolver.Current;
            ILogger logger = dependencyResolver.GetService<ILoggerFactory>().Create("File");
            return logger;
        }

        public void AddModelError(string key, string errorMessage)
        {
            ModelState.AddModelError(key, errorMessage);
        }
    }
}
